package cn.kgc.vue.service.impl;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.vue.entity.Course;
import cn.kgc.vue.service.CourseService;
import cn.kgc.vue.mapper.CourseMapper;
import org.springframework.stereotype.Service;

/**
* @author mengshun
* @description 针对表【sys_course】的数据库操作Service实现
* @createDate 2024-04-17 10:31:01
*/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService{


    @Override
    public ResponseResult coursePage(QueryCondition<Course> queryCondition) {

        Page<Course> coursePage = new Page<>(queryCondition.getPage(), queryCondition.getLimit());
        String courseName = queryCondition.getSearchParams().getCourseName();
        LambdaQueryWrapper<Course> lambda = new QueryWrapper<Course>().lambda();
        lambda.eq(StringUtils.isNotBlank(courseName),Course::getCourseName,courseName)
                .orderByDesc(Course::getCreateTime);

        baseMapper.selectPage(coursePage,lambda);


        return ResponseResult.success()
                .data("total",coursePage.getTotal())
                .data("tableData",coursePage.getRecords());
    }
}




